<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="../error.jsp"%>

<%@page import="java.sql.*"%>

<%@page import="df.jsp.Guard"%>
<%@page import="df.jsp.LabelMap"%>
<%@page import="df.bean.db.conn.DBConnection"%>
<%@page import="df.bean.obj.util.DialogBox"%>
<%@page import="df.bean.db.table.TRN_Error"%>
<%@page import="df.bean.db.table.TrnDaily"%>
<%@page import="df.bean.obj.util.JDate"%>
<%@page import="df.bean.process.ProcessUtil"%>
<%@ include file="../../_global.jsp" %>
<%@page import="df.bean.obj.util.Utils"%>

<%
            //
            // Verify permission
            //

            if (!Guard.checkPermission(session, Guard.PAGE_PROCESS_DEMO)) {
                response.sendRedirect("../message.jsp");
                return;
            }
				ProcessUtil proUtil = new ProcessUtil();
				LabelMap labelMap = new LabelMap(session.getAttribute("LANG_CODE").toString());
				labelMap.add("TITLE_MAIN", "Payment Summary", "Payment Summary");
				labelMap.add("DATE", "Date", "Date");
				labelMap.add("END_DATE", "End Date", "วันที่สิ้นสุด");
				labelMap.add("MM", "Month", "เดือน");
				labelMap.add("YYYY", "Year", "ปี");
				labelMap.add("COL_3", "Status", "สถานะ");
				labelMap.add("COL_5", "Payment Summary", "Payment Summary");
				request.setAttribute("labelMap", labelMap.getHashMap());
				
				String startDateStr = JDate.showDate(JDate.getDate());
	            String hospitalCode = session.getAttribute("HOSPITAL_CODE").toString();

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>${labelMap.TITLE_MAIN}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <link rel="stylesheet" type="text/css" href="../../css/share.css" media="all" />
        <link rel="stylesheet" type="text/css" href="../../css/epoch_styles.css" />
        <script type="text/javascript" src="../../javascript/epoch_classes.js"></script>
        <link rel="stylesheet" type="text/css" href="../../css/default/easyui.css" />
        <link rel="stylesheet" type="text/css" href="../../css/icon.css" />
        <script type="text/javascript" src="../../javascript/jquery-1.6.min.js"></script>
        <script type="text/javascript" src="../../javascript/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../javascript/jquery-ui-1.8.16.custom.min.js"></script>
        <script type="text/javascript">
	        function timedCount(sce,maxSceond){
	        	document.getElementById('showCount').innerHTML=c+"/"+maxSceond;
	        	c=c+1;
	        	if(c<=maxSceond){
	        		t=setTimeout("timedCount("+c+","+maxSceond+")",150);
	        	}
	        }
 			function confirm(){
				$.messager.confirm('ยืนยันการทำงาน', 'คุณได้ทำ Process Adjustment Summary แล้วหรือยัง?', function(r){
					if(r){
						var date = $("#DATE").val();
			        	var hospitalCode = $("#hospitalCode").val();
						var buttonRun = document.getElementById('RUN');
			        	var img = document.getElementById('imgStatus');
						c=0;
		    			img.src = '../../images/processing_icon.gif';
				       	$.ajax({
							type: "GET",
							url: "../../ProcessCalculateSrvl",
							data: {mode:"paymentSummmary",date:date,hospitalCode:hospitalCode},
							contentType: "application/json; charset=utf-8",
							dataType: "json",
							success: function(data){
								//alert("data.dataSize => " + data.dataSize + " data.check => " + data.check);
								document.getElementById("PROGRESS").innerHTML = data.dataSize +" / " + data.dataSize;
								if(data.check){
				         			img.src = "../../images/succeed_icon.gif";
									alert("      complete!!!!   ");
				         	 	}else{
				         			img.src = "../../images/failed_icon.gif";
									document.getElementById("PROGRESS").innerHTML = 0 +" / " + data.dataSize;
									alert("      Insert Fail!!!!   ");
					        	}
							},
							error: function(xhr,state,exception) { 
			         			img.src = "../../images/failed_icon.gif";
								//alert("xhr => " + xhr + " state => " + state + " exception => " + exception );
								alert("      Insert Fail!!!!   ");
								}
						});
					}
				});
			} 
	        window.onload = function () {
	            var dp_cal;
	            dp_cal  = new Epoch('epoch_popup','popup',document.getElementById('DATE'),document.getElementById('showDate1'));
	        };
	        
	        function chooseStartDate(){
				var dp_cal;
				dp_cal  = new Epoch('epoch_popup','popup',document.getElementById('DATE'),document.getElementById('showDate1'));
	        }
/* 			function runProcess(){
	        	var hospitalCode = DWRUtil.getValue('hospitalCode');
	        	var date = DWRUtil.getValue('DATE');
	        	var img = document.getElementById('imgStatus');
				var buttonRun = document.getElementById('RUN');
    			img.src = '../../images/processing_icon.gif';
	        	buttonRun.disabled = true;
	        	ProcessAjaxCalculate.paymentSummury(hospitalCode, date, function(data){
					document.getElementById("PROGRESS").innerHTML = data.count +" / " + data.count;
					if(data.check){
	         			img.src = "../../images/succeed_icon.gif";
						alert("      complete!!!!   ");
	         	 	}else{
	         			img.src = "../../images/failed_icon.gif";
						document.getElementById("PROGRESS").innerHTML = 0 +" / " + data.count;
						alert("      Insert Fail!!!!   ");
		        	}
				buttonRun.disabled = false;
            	});
			} */
        </script>

    </head>
    <body>
        <form id="mainForm" name="mainForm" method="post" action="ProcessPayMentMonthly.jsp">
			<input type="hidden" id="hospitalCode" name="hospitalCode" value="<%=hospitalCode%>"/>
            <center>
                <table width="800" border="0">
                    <tr><td align="left">
                            <b><font color='#003399'><%=Utils.getInfoPage("forms/process/ProcessPaymentMonthly.jsp", labelMap.getFieldLangSuffix(), new DBConnection(""+session.getAttribute("HOSPITAL_CODE")))%></font></b>
                    </td></tr>
                </table>
            </center>
            	<table class="form" border="1">
            		<tr class="label" style="background: #666666">
            			 <th colspan="2">${labelMap.TITLE_MAIN}</th>
            		</tr>
            		<tr align="center">
            		<td class="label" align="right" width="40%">${labelMap.DATE}</td>
                    <td class="input" valign="middle" width="60%" align="left">
                        <input type="text" value="<%=startDateStr%>" id="DATE" name="DATE" class="short"/>
                         <a href="#" class="position"><img onclick="chooseStartDate();"  id="showDate1" class="" src="../../images/calendar_button.png"/></a>    
                    </td>
                   </tr>
                	<tr>
                    	<th colspan="2" class="buttonBar">
                        	<input type="button" id="RUN" name="RUN" class="button" value="${labelMap.RUN}" onclick="confirm()"/>
                        	<input type="button" id="STOP" name="STOP" class="button" value="Stop" onclick="STOP_Click()" disabled="disabled" />
                        	<input type="button" id="CLOSE" name="CLOSE" class="button" value="${labelMap.CLOSE}" onclick="window.location='../process/ProcessFlow.jsp'" />
						</th>
					</tr>	
            	</table>
            	
            	 <hr />
            <table class="data" id="dataTable" name="dataTable">
                <tr>
                    <th colspan="2" class="alignLeft">
                        <div style="float: left;">${labelMap.TITLE_MAIN}</div>
                        <div style="float: right;" id="PROGRESS" name="PROGRESS"></div>
                    </th>
                </tr>
                <tr>
                    <td class="sub_head"><%=labelMap.get("COL_5")%></td>
<%--                    <td class="sub_head"><%=labelMap.get("COL_2")%></td>    --%>
                    <td class="sub_head"><%=labelMap.get("COL_3")%></td>
                </tr>
                
                <tr>
                    <td class="" align="center"><%="Process Payment"%></td>
<%--                    <td class="row<%=i % 2%> alignCenter"><%=""%></td>  --%>
                    <td class="" align="center"><img id="imgStatus" src="../../images/waiting_icon.gif"/></td>
                </tr>
			<script type="text/javascript">
                    document.getElementById("PROGRESS").innerHTML = "0 / 0";
			</script>
            </table>
    		
    	</form>
    </body>
</html>